#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    freopen("../B1050.txt","r",stdin);
    int N;
    cin>>N;
    int total = N;
    vector<int> v;
    while(N--) {
        int temp1=0;
        cin>>temp1;
        v.push_back(temp1);
    }
    sort(v.begin(),v.end());
    
    int m=1,n=1;
    for(int i=sqrt(total);i>=1;i--){
        if(total%i==0) {
            n = i;
            break;
        } 
    }
    if(n==1) {
        m = total;
    } else {
        m = total/n;
    }
    int a[m][n];
    
    int size =v.size()-1;
    int i=0,j=0;
    
    while(total){
        int temp = i;
		for(;j<n-temp;j++) {
            a[i][j] = v[size--];
			--total;
			if(total==0) break;
		}
		if(total==0) break;
		j--;i++;
		for(;i<m-temp-1;i++) {
            a[i][j] = v[size--];
			--total;
			if(total==0) break;			
		}
		if(total==0) break;
		for(;j>=temp;j--) {
            a[i][j] = v[size--];
			--total;	
			if(total==0) break;		
		}
		if(total==0) break;
		j++;i--;
		for(;i>=temp+1;i--) {
            a[i][j] = v[size--];
			--total;
			if(total==0) break;			
		}
		if(total==0) break;
		++i;++j;
	}

    for(int i=0;i<m;i++){
		for(int j=0;j<n;j++) {
            if(j!=n-1) {
                cout<<a[i][j]<<" ";
            } else {
                cout<<a[i][j];
            }
        }
		cout<<endl;
	}
    
    return 0;
}
